package java8._06_使用流收集数据;

import org.junit.Test;

import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class _02_test {



    static class Book {

        public int type;
        public String name;
        public double price;
    }

    @Test
    public void testMind() {

        ArrayList<Book> oneList = new ArrayList<>();

        oneList.stream().collect(Collectors.groupingBy(item -> item.name));


        oneList.stream().collect(Collectors.maxBy(Comparator.comparing(book -> book.price)));

        oneList.stream().collect(Collectors.summingDouble(item -> item.price));

        oneList.stream().collect(Collectors.summarizingDouble(item -> item.price));

        Stream.generate(() -> "?").limit(10).collect(Collectors.joining(","));


        oneList.stream().collect(Collectors.reducing(998.0, book -> book.price, Double::sum));
    }

    @Test
    public void testGJ() throws Exception {

        Stream.generate(Math::random);
        Stream<String> lines = Files.lines(Paths.get("data.txt"), Charset.defaultCharset());
        Stream.empty();
        int[] numbers = {2, 3, 5, 7, 11, 13};
        int sum = Arrays.stream(numbers).sum();

    }

}
